import { listPayType } from '@/api/pay/PayType/index';
function isJSON(str) {
  if (typeof str == 'string') {
    try {
      var obj = JSON.parse(str);
      if (typeof obj == 'object' && obj) {
        return JSON.parse(str);
      } else {
        return false;
      }
    } catch (e) {
      return false;
    }
  }
}

export default async (type, ops) => {
  let res = ref({})
  ops.map(item => {
    res.value[item] = undefined
  })
  let resData = await listPayType()
  let config = resData.rows.find(item => item.typeId == type)?.config.replace(/\/\/\*\*\*.*\*\*\*.*\n/g, '')
  config = isJSON(config)
  if (config) {
    ops.map(item => {
      res.value[item] = config[item]
    })
  }
  return {
    payTypeList: resData.rows, ...res.value
  };
};


